﻿using DenseCRF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FCN
{
   public  class Layer
    {
        public int inChannels;   //输入图像的数目
        public int outChannels;  //输出图像的数目
        public int stride=1;
        public int padding=0;
        public float[] err;
        public float[] L;
        public int w;
        public int h;
        public Matrix[,] weights;
        public Matrix[] y; // 采样函数后神经元的输出,无激活函数
        public Matrix[] d; // 网络的局部梯度,δ值
        public Matrix[] v; // 进入激活函数的输入值
        public float[] basicData;
       
    }
    public class convlayer : Layer
    {
      
        public convlayer(  int _stride,int _padding,int weightswidth = 5,int innum=1,int outnum=6,bool initW=true) 
        {
            stride = _stride;
            padding = _padding;
            inChannels = innum;
            outChannels = outnum;
            if(initW)
            weights = util.initweights(weightswidth, weightswidth, innum, outnum);
            y = new Matrix[outnum];
            d = new Matrix[outnum];
            v = new Matrix[outnum];
            basicData = new float[outnum];
        }
      

    }
    public class Softmaxlayer : Layer
    {

        public Softmaxlayer(int _stride, int _padding, int weightswidth = 5, int innum = 1, int outnum = 6, bool initW = true)
        {
            stride = _stride;
            padding = _padding;
            inChannels = innum;
            outChannels = outnum;
            if (initW)
                weights = util.initweights(weightswidth, weightswidth, innum, outnum);
            y = new Matrix[outnum];
            d = new Matrix[outnum];
            v = new Matrix[outnum];
            basicData = new float[outnum];
        }


    }
    public class Poolinglayer : Layer
    {
       
        public Poolinglayer(int _stride, int innum = 1, int outnum = 6) 
        {
            inChannels = innum;
            outChannels = outnum;
            y = new Matrix[outnum];
            d = new Matrix[outnum];
            stride = _stride;
        }
       
    }
    public class intputlayer : Layer
    {
        public intputlayer( ) 
        {
            
        }
    }
    public class outputlayer : Layer
    {
        public bool isFull=false;
        public outputlayer(bool full=true, int innum = 1, int outnum = 6,int weightswidth=5, bool initW = true)
        {
            inChannels = innum;
            outChannels = outnum;
            basicData = new float[outnum];
            wdata = new float[outnum ][];
            if(initW)
            if (full)
            {
                Random rand = new Random();
                for (int i = 0; i < outnum; i++)
                {
                    wdata[i] = new float[inChannels];
                    for (int j = 0; j < innum; j++)
                    {

                        wdata[i][j] = ((float)rand.Next() / Int32.MaxValue) * 0.1f; ;
                    }
                }
            }
            else
            {
                weights = util.initweights(weightswidth, weightswidth, innum, outnum);
            }
            v = new Matrix[outChannels];
           y = new Matrix[outChannels];
            err = new float[outChannels];
            d= new Matrix[outChannels];
        }


        public float[][] wdata; 
      
    }
}
